﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Smartmanufact
{
    public partial class Frame : PictureBox
    {
        public int row_index=0;
        public int col_index=0;
        public bool empty_is = true;                           // 最开始是空的
        public string shelf = "";
        public Frame()
        {
            InitializeComponent();
            this.Image = Image.FromFile(Application.StartupPath+"\\icon\\frame.png");
            this.Width = this.Image.Width;
            this.Height = this.Image.Height;
            this.BackColor = System.Drawing.Color.White;
        }

        private void Frame_Load(object sender, EventArgs e)
        {

        }

        private void Frame_MouseEnter(object sender, EventArgs e)
        {
            this.BackColor = System.Drawing.Color.Green;
            Cargo_View.shelfname = shelf;
            if(row_index==1 && col_index==1)
            {
                int a = 0;
            }
           
            Cargo_View myview = (Cargo_View)this.Parent.Parent;
            try
            {
                DataSet ds = MainView.mysql.sql_search_database("select * from cargotable where shelf='" + shelf + "' AND shelf_row_index='" + row_index.ToString() + "' AND shelf_col_index='" + col_index.ToString() + "'");
                DataRow dr = ds.Tables[0].Rows[0];
                
                myview.richTextBox1.Text = "货物ID：" + dr[0].ToString() + "\n" + "货物名称：" + dr[1].ToString() + "\n" + "货车种类：" + dr[2].ToString() + "\n" + "货物状态：" + dr[3].ToString() + "\n" + "货架" + dr[5].ToString() + "\n" + "行序号：" + dr[6].ToString() + "\n" + "列序号：" + dr[7].ToString() + "\n" + "客户名：" + dr[8].ToString() + "\n" + "操作者：" + dr[9].ToString() + "\n" + "操作时间：" + dr[10].ToString() + "\n" + "操作方式：" + dr[11].ToString();

            }
            catch { myview.richTextBox1.Text = ""; }
        }

        private void Frame_MouseLeave(object sender, EventArgs e)
        {
            if (empty_is == true) this.BackColor = System.Drawing.Color.White;
            if (empty_is == false) this.BackColor = System.Drawing.Color.YellowGreen;
        }

        private void Frame_Click(object sender, EventArgs e)
        {
            
        }

        private void Frame_DoubleClick(object sender, EventArgs e)
        {
            if (empty_is == true)
            {
                manual_add_cargo view = new manual_add_cargo();
                view.row_index = row_index.ToString();
                view.col_index = col_index.ToString();
                view.shelf = shelf;
                view.Fill_Info();
                DialogResult result=view.ShowDialog();
                if (result == DialogResult.OK)
                {
                    empty_is = false;
                    this.BackColor = System.Drawing.Color.YellowGreen;
                }
                return;
            }
            if(empty_is==false)
            {
                CargoClear view = new CargoClear();
                view.shelf = shelf;
                view.delete_row_index = row_index.ToString();
                view.delete_col_index = col_index.ToString();
                DialogResult result= view.ShowDialog();
                if(result==DialogResult.OK)
                {
                    empty_is = true;
                    this.BackColor = System.Drawing.Color.White;
                }
                return;
            }
        }
    }
}
